package team.soi.cloud.service.goods.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.soi.cloud.service.goods.model.Goods;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * 功能描述: <br/>
 *
 * @author Soi <br/>
 * @version 1.0 2016/8/10 18:38
 * @see
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private transient DiscoveryClient client;

    @Value("${mysqldb.datasource.url}")
    private String jdbcUrl;

    @RequestMapping("/")
    public List<?> list() {
        ServiceInstance instance = client.getLocalServiceInstance();
        List<Goods> list = new ArrayList<Goods>();
        Goods goods = new Goods();
        goods.setId(UUID.randomUUID().toString());
        goods.setName("飘柔");
        goods.setCode("piaorou");
        goods.setPrice(10D);
        list.add(goods);
        logger.info("[host:{},service_id:{}] call [/goods/],return {}", instance.getHost(), instance.getServiceId(), list);
        logger.info("jdbcUrl:{}", jdbcUrl);
        return list;
    }
}
